<template>
	<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
		
	  <el-form-item label="员工编号" prop="wnum" >
	    <el-input v-model="ruleForm.wnum"></el-input>
	  </el-form-item>
	  <el-form-item label="采购数量" prop="pnumber" >
	    <el-input v-model="ruleForm.pnumber"></el-input>
	  </el-form-item>
	  <el-form-item label="采购总价" prop="pprice" >
	    <el-input v-model="ruleForm.pprice"></el-input>
	  </el-form-item>
	  <el-form-item label="采购时间" prop="ptime">
	      <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.ptime" style="width: 100%;"></el-date-picker>
	  </el-form-item>
	  <el-form-item label="备注" prop="premarks" >
	    <el-input v-model="ruleForm.premarks"></el-input>
	  </el-form-item>
	 
	 
	  <el-form-item>
	    <el-button type="primary" @click="submitForm('ruleForm')">添加</el-button>
	    <el-button @click="resetForm('ruleForm')">重置</el-button>
	  </el-form-item>
	</el-form>
</template>

<script>
  export default {
    data() {
      return {
        ruleForm: {
          wnum: '',
          pnumber: '',
		  pprice: '',
		  ptime: '',
		  premarks: ''
        },
        rules: {
          wnum: [
            { required: true, message: '请输入员工编号', trigger: 'blur' },
          ],
          pnumber: [
            { required: true, message: '请输入采购数量', trigger: 'blur' },
          ],
		  pprice: [
		    { required: true, message: '请输入采购总价', trigger: 'blur' },
		  ],
		  ptime: [
		    { type: 'date', required: true, message: '请选择采购时间', trigger: 'change' }, // type: 'date'没去掉
		  ],
		  premarks: [
		    { required: true, message: '请输入备注', trigger: 'blur' },
		  ]
        }
      };
    },
    methods: {
      submitForm(formName) {
		const _this=this
        this.$refs[formName].validate((valid) => {
          if (valid) {
            axios.post('http://localhost:8181/purchase/addPurchase',this.ruleForm).then(function(resp){
				console.log(resp)
				if(resp.data == 'sucess'){
					alert('添加成功')
					_this.$router.push('/PurchaseManage')
				}
			})
          } else {
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>



